import { constantRoutes, asyncRoutes } from '@/router/index.js'
const state = {
  routes: constantRoutes
}
const mutations = {
  setRoutes(state, newRouters) {
    state.routes = [...constantRoutes, ...newRouters]
  }

}
const actions = {
  // 方式2. 在vuex中写
  async filterRoutes(context, menus) {
    const filterRoutes = asyncRoutes.filter(t => menus.indexOf(t.name) > -1)
    context.commit('setRoutes', filterRoutes)
    return filterRoutes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}

